package com.pristine.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pristine.dao.IDoctorMasterDao;
import com.pristine.domain.DepartmentMasterEntity;
import com.pristine.domain.DoctorMasterEntity;
import com.pristine.service.wsdl.DepartmentMasterVO;
import com.pristine.service.wsdl.DoctorMasterVO;
import com.pristine.service.wsdl.IDoctorMasterService;
import com.pristine.util.EntityToVOConverter;
import com.pristine.util.VOToEntityConverter;


@Service("doctorMasterService")
@Transactional
public class DoctorMasterServiceImpl implements IDoctorMasterService{

	@Autowired
	private IDoctorMasterDao doctorMasterDao;
	
	@Override
	public Integer createDoctorMaster(DoctorMasterVO doctorMasterVO){
		DoctorMasterEntity doctorMaster = VOToEntityConverter.convert(doctorMasterVO);
		doctorMasterDao.add(doctorMaster);
		return doctorMaster.getId();
	}
	
	@Override
	public Integer updateDoctorMaster(DoctorMasterVO doctorMasterVO){
		DoctorMasterEntity doctorMaster = VOToEntityConverter.convert(doctorMasterVO);
		doctorMasterDao.update(doctorMaster);
		return doctorMaster.getId();
	}
	
	@Override
	public boolean deleteDoctorMaster(Integer id){
		try {
			DoctorMasterEntity entity = doctorMasterDao.find(id);
			doctorMasterDao.remove(entity);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	@Override
	public DoctorMasterVO getDoctorMasterById(Integer id){
		DoctorMasterEntity doctorMaster = doctorMasterDao.find(id);
		DoctorMasterVO vo = EntityToVOConverter.convert(doctorMaster);
		return vo;
	}

	@Override
	public List<DoctorMasterVO> getAllDoctorMaster() {
		List<DoctorMasterEntity> list = doctorMasterDao.list();
		List<DoctorMasterVO> voList= new ArrayList<DoctorMasterVO>();
		if(CollectionUtils.isNotEmpty(list)){
			for(DoctorMasterEntity entity:list){
				DoctorMasterVO vo = EntityToVOConverter.convert(entity);
				voList.add(vo);
			}
		}
		return voList;
	}
	
}
